home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
-
- #define CELLSIZE 16
-
- int main(int argc,char *argv[])
- {
-
- short int dict[CELLSIZE][256];
- short int tempcell[CELLSIZE];
- int current,found,match,i,j;
- FILE *FI,*FC,*FO;
-
- fprintf(stderr,"\nName Table Creator (C)1999 Chris Covell (ccovell@direct.ca)\n\n");
-
- if(argc>4)
- {
- fprintf(stderr,"Usage: %s imagefile CHRfile NAMfile\n\n",argv[0]);
- return(1);
- }
-
- if(!(FI=argc<3? stdin:fopen(argv[1],"rb")))
- { fprintf(stderr,"%s: Can't open image file\n\n",argv[0]);return(1); }
- if(!(FC=argc<3? stdin:fopen(argv[2],"rb")))
- { fprintf(stderr,"%s: Can't open CHR file\n\n",argv[0]);return(1); }
- if(!(FO=argc<3? stdout:fopen(argv[3],"wb")))
- { fprintf(stderr,"%s: Can't open output file\n\n",argv[0]);return(1); }
-
- current=0;
- found=0;
- match=1;
-
- for(i=0; i<256; i=i+1)
- for(j=0; j<CELLSIZE; j=j+1)
- dict[j][i]=fgetc(FC);
- fclose(FC);
-
- while((tempcell[0]=fgetc(FI))>=0)
- {
- found=0;
- current=0;
-
- for(i=1; i<CELLSIZE; i=i+1)
- tempcell[i]=fgetc(FI);
-
- while((found==0) && (current<256))
- {
- for(i=0; ((i<CELLSIZE) && (match==1)); i=i+1)
- {
- if(tempcell[i] != dict[i][current]) match=0;
- }
- if(match==1)
- {
- fputc((current & 0xFF),FO);
- current=0;
- found=1;
- }
- else current=current+1;
- match=1;
- }
-
- if(found==0)
- fputc(0x00,FO);
-
-
- }
-
- fclose(FO);
- fclose(FI);
-
- return(0);
- }